import React from 'react'
import PropTypes from 'prop-types'
import { routerRedux } from 'dva/router'
import { connect  } from 'dva'
import { Button, Icon,Menu,Dropdown} from 'antd'
import List from './list'
import styles from './index.less'
import Detail from './detail'
import Approved from './approved'
import Edit from './edit'
import IndexList from './IndexList'
function Audit ({ location, dispatch, au, loading }) {
 const { list,detail,pagination,ApprovedsTagBon,DetailTags,Editstags,IndexListBon,electId,autStatus,individualVo} = au
 console.log("detail==22",detail)
 const ListsProps  ={
     autStatus,
     dataSource:list,
     detail,
     pagination,
     query(data){
        dispatch({
            type: 'au/query',
            payload:data
        })
     },
     onDetail(data){
         dispatch({
            type: 'au/detail',
            payload:data
        })
     },
     onEdit(data){
        dispatch({
            type:'au/showEdits',
            payload:data
        })
     },
 }
 const IndexLIstProps ={
     dataSource:list,
     autStatus,
     pagination,
     onPageChange(data){
        dispatch({
            type: 'au/query',
            payload:data
        })
     },
     onRowDouble(data){
        dispatch({
            type: 'au/detail',
            payload:data
        })
     }
 }
 const detailProps = {
     detail,
     individualVo,
     onOk(data){
         if(data.type == 9){
            dispatch({
                type:'au/driverAut',
                payload:{
                    id:data.id,
                    aut:data.aut,
                    page:pagination
                },
            })
         }else{
            dispatch({
                type:'au/manufacture',
                payload:{
                    id:data.id,
                    aut:data.aut,
                    page:pagination
                },
            })
         }
     }
 }
 const ApprovedProps = {
     detail,
     onOk(data){
         dispatch({
            type:'au/Approved',
            payload:{
                data:data,
                page:pagination,
                autStatus:autStatus,
            }
        })
     },

 }
 const editPprops ={
     detail:detail,
     onClose(){
        dispatch({
            type:'au/showDetail',
        })
     },
     onOk(data){
         dispatch({
            type:'au/updates',
            payload:{
                data:data,
                page:pagination
            }
        })
     }
 }
 const onAddOrder = ()=>{
    dispatch({
        type:'au/showAdd'
    })
 }

const handleMenuClick =(e)=>{
    console.log("eeee==2",e)
    dispatch({
        type: 'au/query',
        payload:{
            autStatus:e.key,
            total:0,
            current:1,
            pageSize:10,
        }
    })
}
 const menu = (
    <Menu onClick={handleMenuClick}>
        <Menu.Item key="">全部司机.</Menu.Item>
        <Menu.Item key="0">已认证</Menu.Item>
        <Menu.Item key="5">认证中</Menu.Item>
        <Menu.Item key="6">认证失败</Menu.Item>
        <Menu.Item key="9">未认证</Menu.Item>
    </Menu>
);
const StateType =(e)=>{
    let text =''
    switch(e){
        case '0':
            text = '已认证'
            break;
        case '5':
            text = '认证中'
            break;
        case '6':
            text = '认证失败'
            break;
        case '9':
            text = '未认证'
            break;
        default:
        text = '全部司机'        
    }
    return text
}
const ApprovedsTag ={
    display:ApprovedsTagBon?'block':'none'
}
const DetailTag ={
    display:DetailTags?'block':'none'
}
const Editstag ={
    display:Editstags?'block':'none'
}
const IndexListShow={
    display:IndexListBon?'block':'none'
}
const IndexListHide={
    display:IndexListBon?'none':'block'
}
 const Approveds =()=> <Approved {...ApprovedProps}/>
 const Edits =()=><Edit {...editPprops}/>
 const IndexLists =()=> <IndexList {...IndexLIstProps}/>
  return (
    <div className={styles.centerbox}>
     <div style={IndexListShow}>
         <IndexLists />
     </div>   
     <div style={IndexListHide}>
        <div className={styles.userList}>
            <div className={styles.title}>
            <div className={styles.left}>
                <Dropdown overlay={menu}
                >
                    <a style={{color:'#04021D'}}>
                    {StateType(autStatus)} <Icon type="down" />
                    </a>
                </Dropdown>

            </div>
            {/*<div className={styles.right}><Button className={styles.btnstyle} type="primary" icon="plus" onClick={onAddOrder}>添加订单</Button></div>*/}
            </div>
            <List {...ListsProps}/>
        </div>
        <div className={styles.userInfo}>
            <div style={DetailTag}>
                <Detail {...detailProps}/>
            </div>
            <div style={ApprovedsTag}>
                <Approveds/>
            </div>
            <div  style={Editstag}>
                <Edits/>
            </div>
        </div>
     </div>
    </div>
  )
}

Audit.propTypes = {
  ay: PropTypes.object,
  location: PropTypes.object,
  dispatch: PropTypes.func,
  loading: PropTypes.bool,
}

export default connect(({ au, loading }) => ({ au, loading: loading.models.audituser }))(Audit)
